<template>
<div class="warehouse">
  <div class="warehouse" v-if="showEdit == 0">
    <!-- 编辑页面 -->
      <div class="title">
        <span class="name">区域列表</span> <span class="back" @click="back"> <i class="iconfont icon-fanhui"></i> 返回 </span>
        <el-button type="primary" @click="addArea" :loading="loading">新增区域</el-button>
      </div>
      <div class="card" v-for="(item,index) in tableData" @click="addCard(item)" :key="index">
        <div class="card-top">
          <span>{{item.name}}</span>
          <div class="icon">
            <span @click.stop="handleEdit(item)"> <i style="font-size: 20px;cursor: pointer" class="el-icon-edit"></i></span>
            <span @click.stop="deleteArea(item)"><i style="font-size: 20px;cursor: pointer" class="el-icon-delete"></i></span>
          </div>
        </div>
        <div class="content">
          <span>库位数量：<span class="count">{{item.count}}</span></span>
          <span>区域优先级：{{item.area_order}}</span>
        </div>
      </div>
    <!-- <wh-edit v-else @editClose="editClose" :editWarehouseID="editWarehouseID"></wh-edit> -->
  </div>
  <div v-else-if="showEdit == 1">
    <el-dialog title="编辑区域" :append-to-body="true" :before-close="handleClose" :visible.sync="showEdit">
      <div style="margin-top: -25px">
        <el-tabs>
            <wh-area-edit @editCloses="editCloses" :editAreaID="editAreaID"></wh-area-edit>
        </el-tabs>
      </div>
    </el-dialog>
  </div>
  <wh-location v-else :editAreaID="editAreaID" :areaId="areaId" @listClose=listClose></wh-location>
  <div v-if="addAreas">
    <el-dialog title="新增区域" :append-to-body="true" :before-close="handleClose" :visible.sync="addAreas">
      <div style="margin-top: -25px">
        <el-tabs>
            <wh-area-add @addCloses="addCloses" :codes="codes"></wh-area-add>
        </el-tabs>
      </div>
    </el-dialog>
  </div>
</div>
  
</template>

<script>
import warehouse from '@/model/warehouse'
import LinTable from '@/component/base/table/lin-table'
import WhAreaEdit from './wh-area-edit.vue'
import WhAreaAdd from './wh-area-add.vue'
import WhLocation from './wh-location.vue'
// import BookModify from './book-modify'

export default {
  props: {
    warehouseCode: {
      type: String,
    },
  },
  components: {
    LinTable,
    WhAreaEdit,
    WhAreaAdd,
    WhLocation
    // BookModify,
  },
  data() {
    return {
      refreshPagination: true, // 页数增加的时候，因为缓存的缘故，需要刷新Pagination组件
      currentPage: 1, // 默认获取第一页的数据
      pageCount: 10, // 每页10条数据
      total_nums: 0, // 分组内的用户总数
      tableData: [],
      operate: [],
      showEdit: 0,
      editAreaID: 1,
      addAreas: false,
      code: '',
      areaId: null
    }
  },
  async created() {
    console.log('oadslfns');
    this.loading = true
    this.getAreaList()
    // this.operate = [{ name: '编辑', func: 'handleEdit', type: 'primary' }]
    this.loading = false
  },
  methods: {
    async getAreaList() {
      this.codes = this.warehouseCode
      const res = await warehouse.getAreaList(this.warehouseCode)
      this.tableData = res
      console.log(this.tableData)
    },
    handleClose(done) {
      this.showEdit = 0
      console.log(done);
      done()
    },
    addCard(item) {
      console.log(item.id);
      this.showEdit = 2
      this.areaId = item.id
    },
    handleEdit(val) {
      console.log('val', val)
      this.showEdit = 1
      this.editAreaID = val.id
    },
    addCloses() {
      this.addAreas = false
      this.getAreaList()
    },
    listClose() {
      console.log(2222);
      this.showEdit = 0
      this.getAreaList()
    },
    addArea() {
      console.log(this.addAreas);
      this.addAreas = true
    },
    async deleteArea(e) {
      const res = await warehouse.deleteArea(e.id)
      console.log(res);
      this.getAreaList()
    },
    rowClick() {},
     editCloses() {
      this.showEdit = 0
      this.getAreaList()
    },
    editClose() {
      this.showEdit = 2
      this.getAreaList()
    },
    back() {
      this.$emit('editClose')
    },
  },
}
</script>

<style lang="scss" scoped>
.card {
 width: 390px;
 height: 90px;
 background: rgb(234, 234, 238);
 background: linear-gradient(344deg, #fff 0%, rgb(241, 240, 240) 70%);
 box-shadow: 4px 6px 14px #9e9ea3;
 border-radius: 3px;
 color: #000;
 padding: 16px;
 transition: all .3s;
 margin-right: 20px;
 margin-bottom: 40px;
 .card-top {
   display: flex;
   justify-content: space-between;
   .icon {
     span {
       margin-right: 10px;
     }
   }
 }
 .content {
   margin-top: 50px;
   font-size: 14px;
   .count {
    color: #19C6A4;
    font-size: 16px;
   }
   span {
    margin-right: 40px;
   }
 }
}

.card:hover {
 margin-top: -30px;
}
.title {
  width: 100%;
  margin-bottom: 50px;
  padding-bottom: 20px;
  border-bottom: 1px solid #eee;
  .back {
    float: right;
    cursor: pointer;
  }
  .name {
    margin-right: 30px;
  }
}
.warehouse {
  padding: 20px;
}
.warehouse {
  width: 100%;
  display: flex;
  flex-wrap: wrap;
  .box-card {
    width: 500px;
    margin-right: 20px;
    margin-bottom: 30px;
    .code {
      font-size: 22px;
      font-weight:bolder;
      margin-bottom: 10px;
    }
    .item {
      margin-bottom: 15px;
    }
  }
}
</style>
